package com.tsingteng.cosfun.ui.message.comment.usercomment;

import android.os.Bundle;
import android.text.SpannableString;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.tsingteng.cosfun.R;
import com.tsingteng.cosfun.bean.Bean;
import com.tsingteng.cosfun.bean.PlayCommont;
import com.tsingteng.cosfun.ui.message.geneal.PlayDetailsAdapter;
import com.tsingteng.cosfun.ui.mine.HomeMineFragment;
import com.tsingteng.cosfun.ui.mine.TerminalActivity;
import com.tsingteng.cosfun.utils.ImageUtils;
import com.tsingteng.cosfun.utils.SPUtils;
import com.tsingteng.cosfun.utils.StringUtils;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * @我。赞我。评论我页面点击展示段子评论页适配器 常胜
 * 2018.8.23
 */
public class UserCommentAdapter extends BaseQuickAdapter<Bean.DataBeanX.DataBean, BaseViewHolder> {
    private UserCommentAdapter.OnPlayDetailClickListener onAdapterFunctionListener;

    public UserCommentAdapter() {
        super(R.layout.item_user_comment_adapter);
    }

    @Override
    protected void convert(BaseViewHolder helper, Bean.DataBeanX.DataBean item) {
        CircleImageView headerView = helper.getView(R.id.iv_header);
        TextView mUpName = helper.getView(R.id.tv_name_up);
        TextView mUpComment = helper.getView(R.id.tv_comment_up);
        TextView mAuthor = helper.getView(R.id.tv_author);
        TextView mDownName = helper.getView(R.id.tv_name_down);
        TextView mDownComment = helper.getView(R.id.tv_comment_dowm);
        TextView mTime = helper.getView(R.id.tv_comment_time);
        ImageView mCreat = helper.getView(R.id.iv_great);
        TextView mGreatNum = helper.getView(R.id.tv_great_num);
        ImageView iv_header = helper.getView(R.id.iv_header);
        mTime.setText(item.getFormatTime());
        LinearLayout ll_great = helper.getView(R.id.ll_great);
        TextView tv_operator = helper.getView(R.id.tv_operator);
        tv_operator.setVisibility(View.GONE);

            mAuthor.setText("作者");

            ImageUtils.LoadImage(mContext, item.getImage(), headerView);
            mDownName.setVisibility(View.GONE);
            mDownComment.setVisibility(View.GONE);
            setText(mUpName, item.getNickName());
        String content = StringUtils.matchReplaceTxt(item.getCommentContent());
        SpannableString msp = StringUtils.getWeiBoContents(content, mUpComment,onAdapterFunctionListener);
            mUpComment.setText(msp);
        if (item.getPraiseStatus()==0) {
            mCreat.setImageDrawable(mContext.getResources().getDrawable(R.drawable.great_icon));
        }else {
            mCreat.setImageDrawable(mContext.getResources().getDrawable(R.drawable.great_pink_icon));
        }

        ll_great.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onAdapterFunctionListener !=null) {
                    onAdapterFunctionListener.onPraiseClick(item,mCreat,mGreatNum);
                }
            }
        });
        setText(mGreatNum,item.getPCount());

        iv_header.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Bundle bundle = new Bundle();
                bundle.putInt("tag", 3);
                bundle.putInt("user_id", item.getProfileId());
                bundle.putInt("workId",item.getCommentId());
                TerminalActivity.showFragment(mContext, HomeMineFragment.class, bundle);
            }
        });
    }

    public void setText(TextView textView, String text) {
        if (textView == null || TextUtils.isEmpty(text)) return;
        textView.setText(text);
    }


    public void setOnPlayDetailClickListener(UserCommentAdapter.OnPlayDetailClickListener onPlayDetailClickListener) {
        this.onAdapterFunctionListener = onPlayDetailClickListener;
    }
    public interface OnPlayDetailClickListener{
        void onPraiseClick(Bean.DataBeanX.DataBean item, ImageView mCreat, TextView mGreatNum);
        void onUserClick(String userId);
    }
}
